<?php
/**
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 3 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
*/

/**
 * Abstract Helper for helpers
 * @package Core
 * @subpackage View.Helper
 * @category Abstract
 * @author kovacsricsi
 * @author Vincze Tam�s pilou@pilou.hu
 * @version 0.3 
 */
namespace Core\View\Helper;

abstract class Helper
{
	/**
	 * Attributes for heleper.
	 * @access protected
	 * @var array
	 */
	 protected $_attributes = array();

	/**
	  * Suffix the href or src with a timestam to disallow caching from config.ini
	  * @var bool
	  */
	 protected $_useTimestampSuffix = false;
	 
	 /**
	  * Gets the attributes array
	  * @return array
	  */
	 public function getAttributes($htmlspecialchars = false){
		 return $this->_createAttributes($htmlspecialchars = false);
	 }
	 
	 
	/**
	 * Create attribute string for herlper.
	 * @access protected
	 * @return string
	 */
	protected function _createAttributes($htmlspecialchars = false, $unset = null)
	{
		$attributes = array();
		settype($unset, "array");

		foreach($this->_attributes as $name => $value) {
			if (!in_array($name, $unset)){
				if ($this->_useTimestampSuffix == true && in_array($name, array("href", "src") )){
					$value .= ((strpos("?", $value) === false) ? "?" : "&") . time();
				}
				$attributes[] = $name . '="' . ( ($htmlspecialchars) ? htmlspecialchars($value, ENT_COMPAT) : $value) . '"';
			}
		}

		return " " . join(" ", $attributes) . " ";
	}

	/**
	 * Returns with helper string.
	 * @access public
	 * @return string
	 */
	abstract public function getHelper();
}

?>